#include <globals.au3>

Func deo_traycbevent($num)
  local $clip = $cbb[$num-1]
  local $a
  $clicked = 1
  
  if ClipGet() == $clip then 
    return
  EndIf
  
  if $num <= $traytotalnum then
    for $a=$num-1 to $traytotalnum-2 step 1
      TrayItemSetText($traycb[$a],TrayItemGetText($traycb[$a+1]))
      $cbb[$a] = $cbb[$a+1]
    next
  EndIf
  
  TrayItemSetState($traycb[$num-1],$TRAY_UNCHECKED)
  TrayItemSetState($traycb[0],$TRAY_CHECKED)

  if ($clip<>"") then
    ClipPut($clip)
  EndIf
EndFunc

Func deo_entry_add()
  SaveClipToFile($cb)

  If ($traytotalnum < $clip_entries_size) and ($clicked == 0) Then
    $traytotalnum += 1
    $traycb[$traytotalnum-1] = TrayCreateItem("<empty>",-1,$traytotalnum,1)
    TrayItemSetOnEvent($traycb[$traytotalnum-1],"traycbevent"&$traytotalnum)
    TrayItemSetState($traycb[0],$TRAY_CHECKED)
  ElseIf $clicked == 1 Then
    $clicked = 0
  EndIf
  
  $lc = $cb
  for $a=$traytotalnum-1 to 1 step -1
		TrayItemSetText($traycb[$a],TrayItemGetText($traycb[$a-1]))
		$cbb[$a] = $cbb[$a-1]
	next
	$cbb[0] = $cb
	TrayItemSetText($traycb[0],shorten($cb))
EndFunc
